<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <video id="local-video"></video>
    <script>
        var myMediaDevices = navigator.mediaDevices;
        myMediaDevices.ondevicechange = (e) => {
            console.log("ondevicechange: ", e)
        }

        function a() {
            if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
                console.log("不支持 enumerateDevices() .");
                return;
            }
            myMediaDevices
                .enumerateDevices()
                .then(function (devices) {
                    devices.forEach(function (device) {
                        console.log(
                            // device.kind + ": " + device.label + " id = " + device.deviceId,
                            device
                        );
                    });
                })
                .catch(function (err) {
                    console.log(err.name + ": " + err.message);
                });

        }
        a()

        // while(true){

        // }
    </script>

</body>

</html>